package com.practice.gmall.realtime.functions;

import com.practice.gmall.realtime.util.CommonUtil;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;

import java.io.IOException;
import java.util.List;

/**
 * ClassName: SplitZnWords
 * Package: com.practice.gmall.realtime.functions
 * Description: 自定义UDTF函数，将输入的字符串按照中文习惯切分并输出
 *
 * @Author lzy.ethan@qq.com
 * @Create 2023-02-17 10:27
 */
@FunctionHint(output = @DataTypeHint("ROW<word String>"))
public class SplitZnWords extends TableFunction<Row> {
    public void eval(String str) throws IOException {
        List<String> strings = CommonUtil.splitZnWords(str);
        for (String string : strings) {
            collect(Row.of(string));
        }
    }
}
